package org.alanlau.springjpa.controller;

import org.alanlau.springjpa.entity.Person;
import org.alanlau.springjpa.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Person 控制器
 *
 * @author Alan
 * @data 2019/10/13 18:34
 */
@RestController
@RequestMapping("/person")
public class PersonController {
    @Autowired
    PersonService personService;

    @GetMapping
    public List<Person> getPersonList() {
        return personService.getPersons();
    }

    @PostMapping
    public void savePerson(@RequestBody String name) {
        personService.save(name);
    }

    @GetMapping("/{name}")
    public List<Person> getPersonByName(@PathVariable("name") String name) {
        return personService.findNativeByName(name);
    }
}
